from public import view_person

from pylib import models
from pylib import web

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class Restore(web.BaseHandler):

  ALLOWED_CLASSES = [
    models.Person,
    models.Identity,
  ]

  @web.transaction_with_retries
  @web.model_from_request
  def Restore(self, model):
    assert model.__class__ in self.ALLOWED_CLASSES
    model.put(request=self.request)
    return model

  @web.valid_xsrf_token_required
  def post(self):
    model = self.Restore()
    if isinstance(model, models.Person):
      self.internal_redirect(view_person.ViewPerson(), model.key())
    if isinstance(model, models.Identity):
      self.internal_redirect(view_person.ViewPerson(), model.person.key())


application = webapp.WSGIApplication([('.*', Restore)])

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
